<template>
  <div class="server-container">
    <div class="title">日常服务记录</div>
    <el-dialog title="更新记录" :visible.sync="dialogVisible" width="40%"  :before-close="handleClose">
      <!--用户表单信息 --> 
      <el-form ref="form" :rules="rules" :inline="true" :model="form" label-width="80px">
        <el-form-item label="业务编号" prop="busnum">
          <el-input placeholder="请输入业务编号" v-model="form.busnum"></el-input>
        </el-form-item>
        <el-form-item label="登记日期" prop="intime">
          <el-date-picker v-model="form.intime" type="date" placeholder="选择日期" value-format="yyyy-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="老人姓名" prop="eldername">
          <el-input placeholder="请输入老人姓名" v-model="form.eldername"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择">
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="0"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="护理等级" prop="hlLevel">
          <el-select v-model="form.hlLevel" placeholder="请选择">
            <el-option label="一级" value="91"></el-option>
            <el-option label="二级" value="90"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
    <div class="server-header">
      <el-button @click="handleAdd" type="primary">
        + 新增
      </el-button>
      <!-- 查询 -->
      <el-form :inline="true" :model="userform">
        <el-form-item>
          <el-input placeholder="请输入编号" v-model="userform.busnum"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="onSubmit" type="primary">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData" style="width: 100%" stripe>
      <el-table-column prop="busnum" label="业务编号" width="180">
      </el-table-column>
      <el-table-column prop="intime" label="登记日期" width="180">
      </el-table-column>
      <el-table-column prop="eldername" label="老人姓名">
      </el-table-column>
      <el-table-column prop="sex" label="性别">
        <template slot-scope="scope">
          <span>{{ scope.row.sex == 1 ? '男' : '女'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="hlLevel" label="护理级别">
        <template slot-scope="scope">
          <span>{{ scope.row.sex == 90 ? '一级' : '二级'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button size="mini" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination layout="prev, pager, next" :total="total" @current-change="handlePage">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getData } from '../api'
export default {
  name: "serve",
  data() {
    return {
      dialogVisible: false,
      userform:{
        //查询字段 busnum: '',
      },
      form: {
        busnum: '',
        intime: '',
        eldername: '',
        sex: '',
        hlLevel: '',
      },
      tableData: [{
        busnum: '101',
        intime: '',
        eldername: 'pp',
        sex: '0',
        hlLevel: '91',
      }],
      total: 50,//当前的总条数
      modalTyoe: 0,//弹窗编号：1编辑；0增添
      pageData:{
        page: 1,
        limit: 10
      },
      rules: {
        eldername: [
          { required: true, message:'请输入姓名'},
          { required: true, pattern: /^[\u0391-\uFFE5A-Za-z]+$/, message: '姓名应为中文字符', trigger: 'blur'}
        ],
        busnum: [
          { required: true, message:'请输入业务编号'},
          { required: true, pattern: /^[1-9]\d*$/, message: '业务编号应为正整数', trigger: 'blur'}
        ],
        intime: [
          { required: true, message:'请设置入住时间'}
        ],
        sex: [
          { required: true, message:'请选择性别'}
        ],
        hlLevel: [
          { required: true, message:'请选择护理类别'}
        ],
        
      }
    }
  },
  methods: {
    //提交
    submit() {
      this.$refs.form.validate((valid) => {
        console.log(valid,'valid')
        if (valid) {
            //后续对表单数据的处理
            if (this.modalTyoe === 0) {
              //新增接口调用
            } else {
              //编辑接口调用
            }
            console.log(this.form, 'form')
            this.$refs.form.resetFields()
            this.dialogVisible = false
        }
      })
    },
    //弹窗关闭
    handleClose() {
      this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    cancel() {
      this.handleClose()
    },
    handleEdit(row) {
      this.modalTyoe = 1
      this.dialogVisible = true
      //需要对当前行数据进行深拷贝,否则会出错
      this.form = JSON.parse(JSON.stringify(row))
    },
    handleDelete(row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        //删除接口（通过ID）
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    handleAdd() {
      this.modalTyoe = 0
      this.dialogVisible = true
    },
    //获取列表数据
    //getList() 
    //this.total = data.count : 0（总条数）

    //选择页面的回调
    handlePage(val) {
      console.log(val,'val')
    },
    //列表搜索条件
    onSubmit() {

    }
  },
  mounted () {
    //this.getList()
    getData().then((data) => {
      console.log(data)
    })
  }
}
</script>

<style scoped>

.server-container {
  width: 80%;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-content: center;
}
.title {
  border-bottom: 1px solid #87bab4;
  height: 50px;
  font-size: 24px;
  border-left: 5px solid lightskyblue;
  padding-left: 30px;
  line-height: 40px;
}

.server-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}

.server-header .el-form .el-form-item {
  margin-bottom: 0;
}
</style>